<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图区域 -->
        <el-card>
            <!-- 搜索区域 -->
            <el-row :gutter="20">
                <el-col :span="8">
                    <el-input placeholder="请输入内容" clearable v-model="queryInfo.query" @clear="getOrderList">
                        <template #append>
                            <el-button :icon="Search" @click="searchOrder" />
                        </template>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 订单列表区域 -->
            <el-table :data="orderList">
                <el-table-column type="index"></el-table-column>
                <el-table-column label="订单编号" prop="order_number"></el-table-column>
                <el-table-column label="订单价格" prop="order_price"></el-table-column>
                <el-table-column label="订单状态" prop="order_status">
                    <!-- <template #default="scope">
                    <el-tag type="success" v-if="scope.row.order_status === 1">已付款！</el-tag>
                    <el-tag type="danger" v-else>未付款！</el-tag>
                </template> -->
                    <template #default="scope">
                        {{ scope.row.order_status === 1 ? '已付款' : '未付款' }}
                    </template>
                </el-table-column>
                <el-table-column label="是否发货" prop="is_send"></el-table-column>
                <el-table-column label="订单时间" width="180">
                    <template #default="scope">
                        {{ formatDate(scope.row.create_time) }}
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template #default>
                        <el-button size="small" type="primary" :icon="Edit" @click="showAddressEditDialog"></el-button>
                        <el-button size="small" type="success" :icon="Location" @click="showExpressDialog"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页区域 -->
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                v-model:current-page="queryInfo.pagenum" :page-sizes="pageSizes" v-model:page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
        </el-card>
        <!--弹出地址编辑对话框-->
        <address-edit ref="AddressEditRef"></address-edit>
        <!--弹出物流信息对话框-->
        <express-dialog ref="ExpressDialogRef"></express-dialog>
    </div>
</template>

<script setup>
import { Search, Edit, Location } from '@element-plus/icons-vue'
import { ref } from 'vue'
import { getOrderListApi } from '@/api/order'

//引入使用方法
import { message } from '@/utils/functions'
import { formatDate } from '@/utils/functions'

//连接子组件
import AddressEdit from './components/AddressEdit.vue'
import ExpressDialog from './components/ExpressDialog.vue'


const ExpressDialogRef = ref(null)
// 获取物流信息
const showExpressDialog = () => {
  ExpressDialogRef.value.open()
}

const AddressEditRef = ref(null)
// 打开修改地址对话框窗
const showAddressEditDialog = () => {
  // 显示弹层
  AddressEditRef.value.open()
}

//创建分页长度
const pageSizes = ref([10, 20, 30])
//构建分页参数
const queryInfo = ref({
    query: '',
    pagenum: 1,
    pagesize: 10
})
//导入订单列表数据
const orderList = ref([])
const total = ref(0)
const getOrderList = async () => {
    const data = await getOrderListApi(queryInfo.value)
    console.log(data)
    orderList.value = data.goods
    total.value = data.total
}
getOrderList()

//监听页码值改变
//1）每页显示条数改变时触发
const handleCurrentChange = (newPage) => {
    queryInfo.value.pagenum = newPage
    getOrderList()
}
//2）当前页码值改变时触发
const handleSizeChange = (newSize) => {
    queryInfo.value.pagesize = newSize
    getOrderList()
}
</script>

<style lang="scss" scoped></style>